package nc.tb.app.adjustbill.ui;

import javax.swing.JComponent;

import nc.ui.bd.ref.AbstractRefModel;
import nc.ui.pub.beans.UIRefPane;
import nc.ui.querytemplate.QueryConditionEditorContext;
import nc.ui.querytemplate.filtereditor.DefaultFilterEditor;
import nc.ui.querytemplate.meta.FilterMeta;
import nc.ui.querytemplate.valueeditor.DefaultFieldValueEditor;

public class EntityFilterEditor extends DefaultFilterEditor{

	private String systemCode = null;
	
	public EntityFilterEditor(QueryConditionEditorContext context, FilterMeta meta) {
		super(context, meta);
		initialize();
	}
	
	public EntityFilterEditor(QueryConditionEditorContext context, FilterMeta meta, String systemCode) {
		super(context, meta);
		this.systemCode = systemCode;
		initialize();
	}
	
	private void initialize(){
		UIRefPane lur = (UIRefPane)getEditorCmpnt(this);
//		lur.setCacheEnabled(false);
		lur.setRefModel(getNtbEntityModel(systemCode));
		UIRefPane rur = (UIRefPane)getRightEditorCmpnt(this);
//		rur.setCacheEnabled(false);
		rur.setRefModel(getNtbEntityModel(systemCode));
	}
	
	private AbstractRefModel getNtbEntityModel(String systemCode){
		return new NtbEntityModel(systemCode);
	}
	
	private static JComponent getEditorCmpnt(DefaultFilterEditor dfe){
		DefaultFieldValueEditor dfve = (DefaultFieldValueEditor)dfe.getFieldValueEditor();
		return dfve.getFieldValueElemEditor().getFieldValueElemEditorComponent();
	}
	
	private static JComponent getRightEditorCmpnt(DefaultFilterEditor dfe){
		DefaultFieldValueEditor dfve = (DefaultFieldValueEditor)dfe.getFieldValueEditor();
		return dfve.getRightFieldValueElemEditor().getFieldValueElemEditorComponent();
	}

}
